<%@page import="wt.workflow.definer.UserEventVector"%>
<%@page import="shmged.com.shlcm.workflow.setparticipant.TpCompleteTaskBean"%>
<%@page import="shmged.com.shlcm.workflow.CmWorkFlowHelper"%>
<%@page import="wt.httpgw.URLFactory"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="wt.workflow.engine.ProcessData"%>
<%@page import="wt.workflow.engine.WfVariable"%>
<%
	String baseUrl = new URLFactory().getBaseHREF();
	TpCompleteTaskBean taskBean = TpCompleteTaskBean.newTpCompleteTaskBean(request);
	
%>
<html>
<head>
<title><%=taskBean.getActiveName() %></title>
<link rel="stylesheet" type="text/css" href="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript">var pageBaseUrl = "<%=baseUrl%>";</script>
<script type="text/javascript" src="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=baseUrl%>shmged/jsp/com/shlcm/portal/js/main.js"></script>
<style type="text/css">
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
</style>
</head>
<body>
<div align="center">
	<div style="margin: 10px 0;"></div>
	<div title="<%=taskBean.getActiveName()%>"
		style="width: 800px;" align="center">
		<div style="margin: 10px 0;"></div>
		<form method="post" enctype="multipart/form-data" name="commitWork"
			id="commitWork">
			<table width="100%">
				<tr>
					<td width="80px" align="right">任务名称:</td>
					<td><%=taskBean.getActiveName()%></td>
				</tr>
				<tr>
					<td align="right">主题:</td>
					<td><a href='<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/browseShowReimbursement.jsp?oid=<%=taskBean.getTpoid() %>'
						><%=taskBean.getTpSubject()%></a></td>
				</tr>
				<tr>
					<td align="right">活动指令:</td>
					<td></td>
				</tr>
				<tr>
					<td align="right">
					</td><td><%=taskBean.getActivityDescription() %></td>
				</tr>
				<tr>
					<td align="right">状态:</td>
					<td><%=taskBean.getTpState()%></td>
				</tr>
				<%
					ProcessData tpwaData =  taskBean.getActivityData();
				    ProcessData tpflowData = taskBean.getWorkflowData();
					if(null != tpwaData && null != tpflowData){
						WfVariable dvar = tpwaData.getVariable("TpDisplayVar");
						String displayStr = null;
						if(null != dvar){
							displayStr = (String)dvar.getValue();
						}
						String [] varNames;
						if(null == displayStr || displayStr.trim().length() == 0){
							varNames = new String[0];
						}else{
							varNames = displayStr.trim().split(";");
						}
					  for(int tpi = 0 ;tpi < varNames.length;tpi++){
						  WfVariable flowVar = tpflowData.getVariable(varNames[tpi]);
						  if(null == flowVar){
							  continue;
						  }
				%>
				<tr>
					<td align="right"><%=flowVar.getDisplayName()%>:</td>
					<td><%=null == flowVar.getValue() ? "": flowVar.getValue()%></td>
				</tr>
				<%
					  }
					}
					
					if(null == tpwaData || !"true".equals(tpwaData.getValue("tpNoDisplayInputComments"))){
						
				%>
				<tr>
					<td align="right">意见:</td>
					<td><textarea id="userComments" name="userComments" cols="45"
							rows="5"></textarea></td>
				</tr>
				<%
					}
					if(taskBean.isSetupParticipants()){
				%>
				<tr>
					<td colspan="2"><br />
						 <br /> <%@ include
							file="/shmged/jsp/com/shlcm/workflow/setparticipant/tpTaskFormTemplate.jsp"%>
						<br />
						</td>
				</tr>
				<%}%>
				<%
				UserEventVector eventsV = taskBean.getUserEvent();
					for(int i=0;i<eventsV.size();i++){
						String mychecked ="";
						if(i == 0 ){
							mychecked ="checked='checked'";
						}
				%>
				<tr>
				    <td></td>
					<td align="left"><%=eventsV.get(i)%><input
						type="radio" name="userEvent" value="<%=eventsV.get(i)%>" <%=mychecked %>></input></td>
				</tr>
				<%}%>

				<tr>
					<td align="right" colspan="4">
					<br/>
					<label> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="commitWorkItem()">完成任务</a>
					</label></td>
				</tr>
				<tr>
				  <td colspan="2">
				  签审信息
				  <table id="signInfoId"></table>
				  </td>
				</tr>
				
			</table>
		</form>
	</div>

	<script type="text/javascript">
function commitWorkItem(){
	    var userEvent = document.getElementsByName("userEvent");
	    var select="";
		for(var i=0;i<userEvent.length;i++){
			if(userEvent[i].checked){
				select=userEvent[i].value;
			}
		}
		var oid="<%=taskBean.getWorkitemOid()%>";
		var users = "";
		var setUsers = "false";
		if("undefined" != typeof addPrincipalMap){
			if(!validata()){
				return ;
			}
			for(var i = 0 ; i < addPrincipalMap.length; i ++){
				users = users+addPrincipalMap[i].roleName;
				for(var j = 0 ; j < addPrincipalMap[i].userArray.length; j ++){
					users = users + "`"+addPrincipalMap[i].userArray[j];
				}
				if( i < addPrincipalMap.length-1){
					users = users + ":";
				}
			}
			setUsers = "true";
		}
		
		var comments= "";
		if(document.getElementById('userComments')){
			comments=document.getElementById('userComments').value;
		}
		var url='<%=baseUrl%>shmged/jsp/com/shlcm/workflow/setparticipant/tpCompleteWorkItem.jsp';
		var idata = {
				oid : oid,
				select : select,
				users : encodeURIComponent(users),
				comments : comments,
				setUsers : setUsers
	    };
		jQuery.post(url, idata, function(data) {
				if (data.indexOf("SUCCEED") != -1) {
					alert("任务完成,关闭当前窗口");
					window.close();
				} else {
					alert(data);
				}
			});
		}

function subWorkItem(id)
{
	addworkItemPBOTab("","",id);
	
}

function addworkItemPBOTab(tabObj,tabId,oid){
	var defaultTabId = "cmTabs";
	if(tabId){
		defaultTabId = tabId;
	}
	var tabDefault = {
		href:pageBaseUrl+"shmged/jsp/com/shlcm/reimbursement/browseShowReimbursement.jsp?oid="+oid,
		title:"查看信息",
		selected: true,
		closable:true
	};
	var options ;
	if(tabObj){
	    var empty = {};
		options = $.extend(empty,tabDefault,tabObj);
	}else{
		options = tabDefault;
	}
	if($('#'+defaultTabId).tabs("exists",options.title)){
		$('#'+defaultTabId).tabs('select',options.title);
	}else{
	    $('#'+defaultTabId).tabs('add',options);
	}
}
$(function(){ 
	function getWidthByRatio(mratio){
		return 800 * mratio;
	}
	$('#signInfoId').datagrid({ 
		url:'<%=baseUrl%>shmged/jsp/com/shlcm/workflow/setparticipant/tpSignInfos.jsp?oid=<%=taskBean.getWorkitemOid() %>',
		columns:[[
           {field:'activityName',title:'任务名称',width: getWidthByRatio(0.2)},
           {field:'wtprincipal',title:'参与者',width:getWidthByRatio(0.1)},
           {field:'copleteTime',title:'完成时间',width:getWidthByRatio(0.2)},
           {field:'comments',title:'意见',width:getWidthByRatio(0.28)},
           {field:'eventList',title:'路由',width:getWidthByRatio(0.2)}
		]]
	});
}); 
	</script>
</div>
</body>
</html>


